﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Basic4Net.Utility.Common;
using System.Data;
using System.Web.Services;
using Basic4Net.OAWeb.Base;
using Basic4Net.BusinessRules;

namespace Basic4Net.OAWeb
{
    public partial class Main : BasePage
    {

        ////登录者身份，如果返回3为学校管理员，如果返回1，则为局管理员
        //protected int EduType
        //{
        //    get
        //    {
        //        if (Common.GetUserInfo().UserType == 3)
        //            return 3;
        //        else if (Common.GetUserInfo().UserType == 1)
        //            return 1;
        //        return 0;
        //    }
        //}
        protected string _teachcode;
        protected string _teachname;
        protected string _postname;
        protected string _positionname;
        protected string _typename;

        protected int _userid = -1;
        protected string _permit;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["UserID"] != null)
            {
                DESEncrypt des = new DESEncrypt();
                int UserID = int.Parse(Server.UrlDecode(des.DecryptString(Request["UserID"].ToString())));
                Session["UserID"] = UserID;
                this._userid = UserID;
                if (ExistTeacher(UserID))
                {
                    ListTeacherInfo model = GetTeacher(UserID);
                    this._teachcode = model.TEACHCODE;
                    this._teachname = model.TEACHNAME;
                    //this._postname = model.POSTNAME;
                    this._positionname = model.POSITIONNAME;
                    this._typename = model.TYPENAME;

                    this._permit = GetPermit(UserID);

                    this._postname = GetPost(UserID);
                }
            }

        }

        /// <summary>
        /// 修改密码
        /// </summary>
        /// <returns></returns>
        [System.Web.Services.WebMethod]
        public static int UpdatePwd(string oldPwd, string newPwd)
        {
            ////局级
            //EducationUsersLogic eduUserLogic = new EducationUsersLogic();
            //if (Common.GetUserInfo().UserType == 1)
            //{
            //    Hashtable ht = new Hashtable();
            //    ht.Add("RID", Common.GetUserInfo().UID);
            //    ht.Add("Passwd", oldPwd);
            //    int iCount = eduUserLogic.FindCount(ht);

            //    if (iCount == 0) return -1;          //原密码不正确

            //    //重置密码
            //    List<int> list = new List<int>();
            //    list.Add(Common.GetUserInfo().UID);
            //    return eduUserLogic.ResetPwd(newPwd, list);
            //}

            ////校级
            //if (Common.GetUserInfo().UserType == 3)
            //{
            //    TeacherInfoLogic teacherLogic = new TeacherInfoLogic();

            //    Hashtable ht = new Hashtable();
            //    ht.Add("RID", Common.GetUserInfo().UID);
            //    ht.Add("Passwd", oldPwd);
            //    int iCount = teacherLogic.FindAdminCount(ht);

            //    if (iCount == 0) return -1;          //原密码不正确

            //    //重置密码
            //    List<int> list = new List<int>();
            //    list.Add(Common.GetUserInfo().UID);
            //    return teacherLogic.ResetPassword(newPwd, list);
            //}

            return 0;

        }
    }
}